#ifndef SNAKESAPP_H
#define SNAKESAPP_H

#include "kernel/nref.h"
#include "util/narray.h"

#include "snakes/snakes.h"

//------------------------------------------------------------------------------

class nMesh2;
class nTexture2;
class nShader2;
class nResource;

class SnakesApp
{
public:
    
    virtual void Init();
    
    virtual bool Open();
    virtual void Close();
    virtual void Tick( float fTime );

    virtual void Render();

    void RequestQuit( bool bQuit ) { this->bQuitRequested = bQuit; }
    bool IsQuitRequested() { return this->bQuitRequested; }

private:

    enum GameState
    {
        State_Menu = 0,
        State_Score,
        State_Game,
    };

    GameState gameState;
    bool bQuitRequested;

    bool LoadResource( nResource* pResource, const nString& strFilename );

    //initialize structures
    void SetupBoard( SnakeBoard* );
    void SetupSnake( SnakeState* );

    //draw helpers
    int BeginDraw( nShader2* pShader, nMesh2* pMesh );
    void BeginPass( nShader2* pShader, int passIndex );
    void Draw( const vector3& vPosition, const vector3& vScale );
    void EndPass( nShader2* );
    void EndDraw( nShader2* );

    SnakeBoard board;
	nArray<SnakeState> snakes;

    nRef<nMesh2> refBoardMesh;
    nRef<nTexture2> refBoardTexture;
    nRef<nShader2> refBoardShader;

    nRef<nMesh2> refSnakeMesh;
    nRef<nShader2> refSnakeShader;
};

#endif //SNAKESAPP_H
